def prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

number = int(input())

if len(str(number)) != 4 or number < 1000:
    result = 0
else:
    digits = str(number)
    max_num = 0

    for i in range(4):
        for j in range(i + 1, 5):
            num = int(digits[i:j])
            if prime(num) and num > max_num:
                max_num = num

    result = max_num

print(result) 
